﻿using System;
using System.ComponentModel;

namespace Crossroad.Utils.Extensions
{
    public static class ShortExt
    {
        /// <summary>
        /// 转换枚举
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("转换枚举")]
        public static T ToEnum<T>(this short input)
        {
            var type = typeof(T);

            return (T)Enum.ToObject(type, input);
        }       

        /// <summary>
        /// 是否小于等于0。
        /// </summary>
        /// <returns></returns>
        [Description("是否小于等于0")]
        public static bool IsLessOrEqual0(this short input)
        {
            return input <= 0;
        }

        /// <summary>
        /// 是否不等于0。
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("不等于0")]
        public static bool NotEqual0(this short input)
        {
            return input != 0;
        }

        /// <summary>
        /// 是否为空值 0 = 空
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("是否为空值 0 = 空")]
        public static bool IsEmpty(this short input)
        {
            return input == 0;
        }

        /// <summary>
        /// 是否有内容
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("是否有内容 不是NULL 值不能等于0")]
        public static bool Contains(this short? input)
        {
            if (input == null)
                return false;

            return input.Value != 0;
        }

        /// <summary>
        /// 无内容 == null || == 0
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("无内容 == null || == 0")]
        public static bool NotContent(this short? input)
        {
            if (input.IsNull())
                return true;

            return input == 0;
        }

        /// <summary>
        /// short 转 int
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("short 转 int")]
        public static int ToInt(this short input)
        {
            return Convert.ToInt32(input);
        }


    }
}